package com.hotelsystem.reservations.layouts;

import java.awt.FlowLayout;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JPopupMenu.Separator;

import com.hotelsystem.reservations.main.MainMenuView;
import com.hotelsystem.reservations.rooms.Room;
import com.hotelsystem.reservations.rooms.RoomTypesEnum;

/**
 * View of the Room. Shows all Specific properties of a single room in a new
 * panel.
 * 
 * @author vanjiii
 *
 */
public class RoomView {

    private JPanel mainPanel;

    private JLabel roomNumber;
    private JLabel roomType;
    private JLabel isSmokersFree;
    private JLabel roomIcon;
    private Room concreteRoom;
    
    private final String defaultImage = "Pictures/default_room.png";

    public RoomView(Room room) {
        this.concreteRoom = room;
        buildUI();
    }

    private void buildUI() {
        mainPanel = new JPanel();
        BoxLayout mainLayout = new BoxLayout(mainPanel, BoxLayout.Y_AXIS);
        mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        mainPanel.setLayout(mainLayout);

        JPanel roomNumberPanel = new JPanel(new FlowLayout());
        roomNumberPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        roomNumber = new JLabel();
        roomNumber.setText(((Integer) concreteRoom.getRoomNumber()).toString());
        JLabel textRoomNumber = new JLabel("Room Number: ");
        roomNumberPanel.add(textRoomNumber);
        roomNumberPanel.add(roomNumber);

        JPanel roomTypePanel = new JPanel(new FlowLayout());
        roomTypePanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        roomType = new JLabel();
        roomType.setText(concreteRoom.getRoomType().toString());
        JLabel textRoomType = new JLabel("The type of the room: ");
        roomTypePanel.add(textRoomType);
        roomTypePanel.add(roomType);

        JPanel smokersPanel = new JPanel(new FlowLayout());
        smokersPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        isSmokersFree = new JLabel(concreteRoom.isSmokersFree() ? "The room is for non-smokers"
                : "The rooms is for smokers");
        smokersPanel.add(isSmokersFree);

        JPanel picturePanel = new JPanel(new FlowLayout());
        picturePanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        roomIcon = new JLabel();
        if (concreteRoom.getImageFilePath() != null) {
            roomIcon.setIcon(new ImageIcon(concreteRoom.getImageFilePath()));
        } else {
            roomIcon.setIcon(new ImageIcon(defaultImage));
        }
        picturePanel.add(roomIcon);

        mainPanel.add(picturePanel);
        mainPanel.add(roomNumberPanel);
        mainPanel.add(roomTypePanel);
        mainPanel.add(smokersPanel);
    }

//    public static void main(String[] args) {
//        RoomView mainWindow = new RoomView(new Room(3, RoomTypesEnum.ONE_PERSON_ROOM, true,
//                "fixtures/resources/monodevelop.png"));
//        MainMenuView mainMenu = new MainMenuView();
//
//        JPanel main = mainWindow.getMainPanel();
//
//        JFrame frame = new JFrame();
//        frame.setJMenuBar(mainMenu.getMainMenuBar());
//        frame.add(main);
//        frame.setSize(200, 400);
//        frame.setTitle("Hotel System");
//        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//        frame.setVisible(true);
//    }

    public JPanel getMainPanel() {
        return mainPanel;
    }

    public void setMainPanel(JPanel mainPanel) {
        this.mainPanel = mainPanel;
    }

    public JLabel getRoomNumber() {
        return roomNumber;
    }

    public void setRoomNumber(JLabel roomNumber) {
        this.roomNumber = roomNumber;
    }

    public JLabel getRoomType() {
        return roomType;
    }

    public void setRoomType(JLabel roomType) {
        this.roomType = roomType;
    }

    public JLabel getIsSmokersFree() {
        return isSmokersFree;
    }

    public void setIsSmokersFree(JLabel isSmokersFree) {
        this.isSmokersFree = isSmokersFree;
    }

}
